<?php
/**
 * 用户收藏
 *
 * @author kong
 */
namespace Card\Controller;
use Card\Controller\PublicController;
use Card\Model\CardMemberModel;

class UserFavoriteController extends PublicController {
    

    /**
     * 获取用户收藏的商品(用户查看自己)
     * @return [type] [description]
     */
    public function getFavoriteGoods() {

        $data = inputJson();

        $res = $this->is_login($data['phpsid']);
        if(!$res){
            abnormalOutputJson(['info'=>'请先登录','type'=>1]);
        }

        $user_id = $this->get_userId($data['phpsid']);//查用户id
        
        //获取用户信息
        $CardMember = D('CardMember');
        $member_info = $CardMember->getMemberInfo(array('id' => $user_id));

        if(!isset($data['page']) || $data['page'] == '' || intval($data['page'] <= 0)) {
            $page = 1;
        }else{
            $page = $data['page'];
        }

        if(!isset($data['limit']) || $data['limit'] == '' || $data['limit'] <= 1) {
            $limit = 6;
        }else{
            $limit = $data['limit'];
        }

        $arr = array(
            'member_uuid'   =>  $member_info['member_uuid'],
            'page'          =>  $page,
            'limit'         =>  $limit,
            'fav_type'      =>  'goods'
        );

        $result = mall_json_post_http_curl('act=api_weiweishai&op=getUserFavoriteGoods',$arr);

        if(isset($result['status']) && $result['status'] == 1) {
            successOutputJson($result['data']);
        }else{
            if(isset($result['msg']) && $result['msg'] != '') {
                abnormalOutputJson($result['msg']);
            }else{
                errorOutputJson('服务器错误，请稍后再试！');
            }
        }

    }


    /**
     * 查看别人名片的时候，显示别人收藏的商品信息
     * @param  [type] $user_id [description]
     * @return [type]          [description]
     */
    public function getUserFavGoods($user_id) {

        //获取用户信息
        $CardMember = D('CardMember');
        $member_info = $CardMember->getMemberInfo(array('id' => $user_id));

        $arr = array(
            'member_uuid'   =>  $member_info['member_uuid'],
            'page'          =>  1,
            'limit'         =>  3,
            'fav_type'      =>  'goods'
        );

        $result = mall_json_post_http_curl('act=api_weiweishai&op=getUserFavoriteGoods',$arr);
        if(isset($result['status']) && $result['status'] == 1) {
            return array('status'=>1,'list'=>$result['data']['list']);
        }else{
            return array('status'=>0,'list'=>array());
        }

    }


    /**
     * 获取用户收藏的商品(用户查看别人)
     * @return [type] [description]
     */
    public function getOthersFavoriteGoods() {

        $data = inputJson();

        if(!isset($data['card_id']) || $data['card_id'] == '' || $data['card_id'] == 0) {
            abnormalOutputJson('参数错误！');
        }  

        $cart_id = $data['card_id'];//名片id

        //根据cart_id查询用户ID
        $member_id = D('CardId')->getUserId($cart_id);
        
        //获取用户信息
        $CardMember = D('CardMember');
        $member_info = $CardMember->getMemberInfo(array('id' => $user_id));

        if(!isset($data['page']) || $data['page'] == '' || intval($data['page'] <= 0)) {
            $page = 1;
        }else{
            $page = $data['page'];
        }

        if(!isset($data['limit']) || $data['limit'] == '' || $data['limit'] <= 1) {
            $limit = 6;
        }else{
            $limit = $data['limit'];
        }

        $arr = array(
            'member_uuid'   =>  $member_info['member_uuid'],
            'page'          =>  $page,
            'limit'         =>  $limit,
            'fav_type'      =>  'goods'
        );

        $result = mall_json_post_http_curl('act=api_weiweishai&op=getUserFavoriteGoods',$arr);
        
        if(isset($result['status']) && $result['status'] == 1) {
            successOutputJson($result['data']);
        }else{
            if(isset($result['msg']) && $result['msg'] != '') {
                abnormalOutputJson($result['msg']);
            }else{
                errorOutputJson('服务器错误，请稍后再试！');
            }
        }

    }


}